package com.bootdo.system.controller;

import com.bootdo.common.controller.BaseController;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.ArticleDO;
import com.bootdo.system.domain.SceneryArticleDO;
import com.bootdo.system.service.SceneryArticleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RequestMapping("/scenery/article")
@Controller
public class SceneryArticleController extends BaseController {

    private String prefix="system/article"  ;

    @Autowired
    private SceneryArticleService sceneryArticleService;

    @RequiresPermissions("scenery:article:newsList")
    @GetMapping("/newsList")
    String goNewsList(Model model) {
        return prefix + "/newsList";
    }


    @ResponseBody
    @GetMapping("/listNews")
    @RequiresPermissions("scenery:article:newsList")
    public PageUtils listNews(@RequestParam Map<String, Object> params){
        params.put("articleType",1);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    /**
     * 查看
     */
    @GetMapping("/detail")
    public String detail(Long id, Model model,String articleType){
        SceneryArticleDO sceneryArticleDO = sceneryArticleService.get(id,articleType);
        model.addAttribute("sceneryArticleDO", sceneryArticleDO);
        if(articleType.equals("10")){
            return prefix + "/palySbhList_detail";
        }else if(articleType.equals("13")||articleType.equals("14")){
            return prefix + "/walkingList_detail";
        }else{
            return prefix + "/newsList_detail";
        }
    }


    @GetMapping("/add")
    String add(Model model,String type){
        model.addAttribute("attachId", UUID.randomUUID());
        model.addAttribute("articleType", type);
        if(type.equals("10")){
            model.addAttribute("attachIdPlay", UUID.randomUUID());
            return prefix + "/palySbhList_add";
        }else if(type.equals("13")||type.equals("14")){
            model.addAttribute("attachIdPlay", UUID.randomUUID());
            return prefix + "/walkingList_add";
        }else{
            return prefix + "/newsList_add";
        }
    }


    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    public R save(SceneryArticleDO sceneryArticleDO){
        if(sceneryArticleService.save(sceneryArticleDO)>0){
            return R.ok();
        }
        return R.error();
    }


    /**
     * 删除
     */
    @PostMapping( "/remove")
    @ResponseBody
    public R remove( Long id){
        if(sceneryArticleService.remove(id)>0){
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping( "/batchRemove")
    @ResponseBody
    public R remove(@RequestParam("ids[]") Long[] ids){
        sceneryArticleService.batchRemove(ids);
        return R.ok();
    }


    @GetMapping("/edit")
    String edit(Long id,Model model,String articleType){
        SceneryArticleDO sceneryArticleDO = sceneryArticleService.get(id,articleType);
        model.addAttribute("attachId", UUID.randomUUID());
        model.addAttribute("sceneryArticleDO", sceneryArticleDO);
        if(articleType.equals("10")){
            model.addAttribute("attachIdPlay", UUID.randomUUID());
            return prefix + "/palySbhList_edit";
        } else if(articleType.equals("13")||articleType.equals("14")){
            model.addAttribute("attachIdPlay", UUID.randomUUID());
            return prefix + "/walkingList_edit";
        }else{
            return prefix + "/newsList_edit";
        }
    }


    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    public R update(SceneryArticleDO sceneryArticleDO){
        sceneryArticleService.update(sceneryArticleDO);
        return R.ok();
    }


    @RequiresPermissions("scenery:article:noticeList")
    @GetMapping("/noticeList")
    String goNoticeList(Model model) {
        return prefix + "/noticeList";
    }


    @ResponseBody
    @GetMapping("/listNotice")
    @RequiresPermissions("scenery:article:noticeList")
    public PageUtils listNotice(@RequestParam Map<String, Object> params){
        params.put("articleType",2);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    @RequiresPermissions("scenery:article:noteList")
    @GetMapping("/noteList")
    String goNoteList(Model model) {
        return prefix + "/noteList";
    }


    @ResponseBody
    @GetMapping("/listNote")
    @RequiresPermissions("scenery:article:noticeList")
    public PageUtils listNote(@RequestParam Map<String, Object> params){
        params.put("articleType",3);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    @RequiresPermissions("scenery:article:customsList")
    @GetMapping("/customsList")
    String goCustomsList(Model model) {
        return prefix + "/customsList";
    }


    @ResponseBody
    @GetMapping("/listCustoms")
    @RequiresPermissions("scenery:article:customsList")
    public PageUtils listCustoms(@RequestParam Map<String, Object> params){
        params.put("articleType",4);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    @RequiresPermissions("scenery:article:dynamicList")
    @GetMapping("/dynamicList")
    String goDynamicList(Model model) {
        return prefix + "/dynamicList";
    }


    @ResponseBody
    @GetMapping("/listDynamic")
    @RequiresPermissions("scenery:article:dynamicList")
    public PageUtils listDynamic(@RequestParam Map<String, Object> params){
        params.put("articleType",5);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }



    //景区公告
    @RequiresPermissions("scenery:article:scenicNoticeList")
    @GetMapping("/scenicNoticeList")
    String goScenicNoticeList(Model model) {
        return prefix + "/scenicNoticeList";
    }


    @ResponseBody
    @GetMapping("/listScenicNotice")
    @RequiresPermissions("scenery:article:scenicNoticeList")
    public PageUtils listScenicNotice(@RequestParam Map<String, Object> params){
        params.put("articleType",6);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //行业动态
    @RequiresPermissions("scenery:article:dynamicIndustryList")
    @GetMapping("/dynamicIndustryList")
    String goDynamicIndustryList(Model model) {
        return prefix + "/dynamicIndustryList";
    }


    @ResponseBody
    @GetMapping("/listDynamicIndustry")
    @RequiresPermissions("scenery:article:scenicNoticeList")
    public PageUtils listDynamicIndustry(@RequestParam Map<String, Object> params){
        params.put("articleType",7);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //景区简介
    @RequiresPermissions("scenery:article:introductionList")
    @GetMapping("/introductionList")
    String goIntroductionList(Model model) {
        return prefix + "/introductionList";
    }


    @ResponseBody
    @GetMapping("/listIntroduction")
    @RequiresPermissions("scenery:article:introductionList")
    public PageUtils listIntroduction(@RequestParam Map<String, Object> params){
        params.put("articleType",8);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //景区资质
    @RequiresPermissions("scenery:article:qualificationList")
    @GetMapping("/qualificationList")
    String goQualificationList(Model model) {
        return prefix + "/qualificationList";
    }


    @ResponseBody
    @GetMapping("/listQualification")
    @RequiresPermissions("scenery:article:qualificationList")
    public PageUtils listQualification(@RequestParam Map<String, Object> params){
        params.put("articleType",9);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //玩转石板河
    @RequiresPermissions("scenery:article:palySbhList")
    @GetMapping("/palySbhList")
    String goPalySbhList(Model model) {
        return prefix + "/palySbhList";
    }


    @ResponseBody
    @GetMapping("/listPalySbhList")
    @RequiresPermissions("scenery:article:palySbhList")
    public PageUtils listPalySbhList(@RequestParam Map<String, Object> params){
        params.put("articleType",10);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }



    @ResponseBody
    @PostMapping("/sceneryArticleList")
    public PageUtils sceneryArticleList(String articleType,String palyType,String articleTitle,int offset,int limit) {
        Map<String, Object> map= new HashMap<>();
        map.put("articleType",articleType);
        map.put("palyType",palyType);
        map.put("articleTitle",articleTitle);
        map.put("offset",offset);
        map.put("limit",limit);
        //查询列表数据
        Query query = new Query(map);
        List<SceneryArticleDO> sceneryArticleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(sceneryArticleList, total);
        return pageUtils;
    }


    //景区周边
    @RequiresPermissions("scenery:article:surroundingList")
    @GetMapping("/surroundingList")
    String goSurroundingList(Model model) {
        return prefix + "/surroundingList";
    }


    @ResponseBody
    @GetMapping("/listSurrounding")
    @RequiresPermissions("scenery:article:surroundingList")
    public PageUtils listSurrounding(@RequestParam Map<String, Object> params){
        params.put("articleType",11);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }



    //旅游攻略
    @RequiresPermissions("scenery:article:strategyList")
    @GetMapping("/strategyList")
    String goStrategyListList(Model model) {
        return prefix + "/strategyList";
    }


    @ResponseBody
    @GetMapping("/listStrategy")
    @RequiresPermissions("scenery:article:strategyList")
    public PageUtils listStrategyList(@RequestParam Map<String, Object> params){
        params.put("articleType",12);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //印象石板河
    @RequiresPermissions("scenery:article:walkingList")
    @GetMapping("/walkingList")
    String goWalkingList(Model model) {
        return prefix + "/walkingList";
    }


    @ResponseBody
    @GetMapping("/listWalkingList")
    @RequiresPermissions("scenery:article:walkingList")
    public PageUtils listWalkingList(@RequestParam Map<String, Object> params){
        params.put("articleType",13);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //石板河文化
    @RequiresPermissions("scenery:article:cultureList")
    @GetMapping("/cultureList")
    String goCultureList(Model model) {
        return prefix + "/cultureList";
    }


    @ResponseBody
    @GetMapping("/listCultureList")
    @RequiresPermissions("scenery:article:cultureList")
    public PageUtils listCultureList(@RequestParam Map<String, Object> params){
        params.put("articleType",14);
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }


    //首页印象石板河
    @RequiresPermissions("scenery:article:index")
    @GetMapping("/index")
    String goIndex(Model model) {
        SceneryArticleDO sceneryArticleDO=sceneryArticleService.get(null,"15");
        model.addAttribute("sceneryArticleDO", sceneryArticleDO);
        return prefix + "/index";
    }



    /**
     * 查看
     */
    @ResponseBody
    @PostMapping("/sceneryArticleDetail")
    public R detail(Long id,String articleType){
        if(articleType.equals("15")){
            articleType="15";
        }else {
            articleType="";
        }
        SceneryArticleDO sceneryArticleDO = sceneryArticleService.get(id,articleType);
        return R.ok().put("sceneryArticleDO",sceneryArticleDO);
    }

}
